package com.fyzk.activity.chongzhi;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import com.fyzk.base.BaseActivity;
import com.tyjc.lottery.R;
import com.fyzk.view.TopTitleView;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

@ContentView(R.layout.ac_epay)
public class EpayRechargeActivity extends BaseActivity {

	@ViewInject(R.id.topview)
	private TopTitleView topview;

	@ViewInject(R.id.webview)
	private WebView webview;
	@ViewInject(R.id.progress)
	private  ProgressBar progressbar ;

	private String result_url;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		topview.setCenterText("易宝充值");
		topview.setOnTitleClickListener(this);
		result_url = getIntent().getStringExtra("redirectUrl");
		webview.setWebChromeClient(new WebChromeClient(){
			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				super.onProgressChanged(view, newProgress);
				if (newProgress == 100) {
					progressbar.setVisibility(View.GONE);
				} else {
					if (progressbar.getVisibility() == View.GONE)
						progressbar.setVisibility(View.VISIBLE);
					progressbar.setProgress(newProgress);
				}
				super.onProgressChanged(view, newProgress);
			}
		});
		webview.setWebViewClient(new MyWebViewClient());
		webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
		webview.getSettings().setUseWideViewPort(true);
		webview.getSettings().setLoadWithOverviewMode(true);
		webview.getSettings().setSaveFormData(true);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.getSettings().setGeolocationEnabled(true);
		webview.getSettings().setDomStorageEnabled(true);
		webview.loadUrl(result_url);
		webview.requestFocus();
	}

	private class MyWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
//            LogUtils.d("shouldOverrideUrlLoading>>>>"+url);
			return super.shouldOverrideUrlLoading(view, url);
		}



		@Override
		public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
			return super.shouldOverrideKeyEvent(view, event);
		}

		@Override
		public void onPageFinished(WebView view, String url) {
			super.onPageFinished(view, url);
//            LogUtils.d("onPageFinished>>>>" + url);
//            sendMsg(HIDE_PROGRESS, null);
		}

		@Override
		public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
			super.onReceivedError(view, errorCode, description, failingUrl);
		}
	}
//
//	@SuppressWarnings("deprecation")
//	@SuppressLint("SetJavaScriptEnabled")
//	public void rechargeAlipay() {
//		hideSoftInput();
//		mL_main.removeAllViews();
//		WebView web = new WebView(this);
//		web.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
//				LayoutParams.MATCH_PARENT));
//		web.getSettings().setRenderPriority(RenderPriority.HIGH);
//		web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
//		web.requestFocus();
//		web.setVerticalScrollBarEnabled(false);
//		web.setHorizontalScrollBarEnabled(false);
//		web.getSettings().setJavaScriptEnabled(true);
//		web.setWebViewClient(new WeiboWebViewClient());
//		web.loadUrl(result_url);
//		mL_main.addView(web);
//	}
//
//	public void hideSoftInput() throws NullPointerException {
//		InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//		View foucusView = this.getCurrentFocus();
//		if (null == foucusView) {
//			return;
//		}
//		// Log.v(TAG, foucusView.getId()+"");
//		if (inputMethodManager.isActive() && null != foucusView) {
//			inputMethodManager.hideSoftInputFromWindow(
//					foucusView.getWindowToken(),
//					InputMethodManager.HIDE_NOT_ALWAYS);
//		}
//	}
//
//	@Override
//	public String initRechargeType() {
//		return RECHARGE_WAP+"";
//	}
//

}
